package com.funong.matrix.biz.system.pojo.dto;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;


/**
 * 文件ID
 *
 * @author lincl
 */
@Data
@Accessors(chain = true)
public class FileDTO {

    /**
     * 文件ID
     */
    private Integer id;

    /**
     * 转文件列表
     *
     * @param ids
     * @return
     */
    public static List<FileDTO> toList(String ids) {
        if (StrUtil.isBlank(ids)) {
            return new ArrayList<>();
        }
        List<FileDTO> result = new ArrayList<>();
        int[] arr = StrUtil.splitToInt(ids, ',');
        for (int i = 0; i < arr.length; i++) {
            result.add(new FileDTO().setId(arr[i]));
        }
        return result;
    }

    /**
     * 转ids
     *
     * @param fileList
     * @return
     */
    public static String toIds(List<FileDTO> fileList) {
        if (CollUtil.isEmpty(fileList)) {
            return "";
        }
        List<Integer> idList = new ArrayList<>();
        fileList.forEach(item -> idList.add(item.getId()));
        return CollUtil.join(idList, ",");
    }
}
